<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>百度地图</title>
		<style type="text/css">
		</style>
	</head>
	<body>
		<div>
		</div>
		<div id='mapPage'>
			<div id='container'></div>
		</div>
	</body>
	<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
	<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js">
	</script>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=VeNlX17jPLxeiO4BzoL5rb1nyULo4LA9">
	</script>
	<script type="text/javascript">
		document.addEventListener('UniAppJSBridgeReady', function() {
				var map = new BMap.Map("container");
			var mood = plus.storage.getItem('addressList');
			var show = plus.storage.getItem('showWeb');
			mood = JSON.parse(mood)
			let k = 1
			let juli = 0
			for (let i = 0; i < mood.length; i++) {
				let st = {
					lng: mood[i].lng,
					lat: mood[i].lat
				}
				if (mood.length > k + i) {
					let ed = {
						lng: mood[k + i].lng,
						lat: mood[k + i].lat
					}
					juli += cacel(st, ed)
					mood[0].juli = 1
					mood[i + 1].juli = cacel(st, ed)
				}
			}

			mood.sort(sortBy('juli', 1))
			uni.postMessage({
				data: {
					juli: juli,
					mood: mood
				}
			});
			// 181664691616



			function sortBy(attr, rev) {
				if (rev == undefined) {
					rev = 1
				} else {
					(rev) ? 1: -1;
				}
				return function(a, b) {
					a = a[attr];
					b = b[attr];
					if (a < b) {
						return rev * -1
					}
					if (a > b) {
						return rev * 1
					}
					return 0;
				}
			}

			function cacel(st, ed) {
				var pointA = new BMap.Point(st.lng, st.lat); // 创建点坐标A
				var pointB = new BMap.Point(ed.lng, ed.lat); // 创建点坐标B
				var range = map.getDistance(pointA, pointB).toFixed(2); //获取两点距离,保留小数点后两位
				range = (range / 1000).toFixed(2)
				return range * 1
			}
		})
	</script>
</html>